package com.ly.base.chapter04.framwork.mybatis;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.List;

@SpringBootApplication
@MapperScan
public class TestMyBatisPlus {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(TestMyBatisPlus.class, args);
        StudentMapper mapper = context.getBean(StudentMapper.class);

//        test(mapper, List.of("赵一伤","钱二败"));
        test(mapper, List.of());



    }
    static void test(StudentMapper mapper,List<String> names){
        LambdaQueryWrapper<Student> query = new LambdaQueryWrapper<>();
//        query.in(Student::getName,names);
        //query.in(boolen 是否拼接，找到列名，具体数值)  --- 找到列名：禁止使用lambda表达式拼接
        /**
         *  in => in
         *  eq => =
         *  ...
         *  Student::getName => 列名
         */
        query.in(!names.isEmpty(),Student::getName,names);

        for (Student student : mapper.selectList(query)) {
            System.out.println(student);
        }
    }

}
